package com.study.demo_url_mappring.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName: DateConverter
 * @Description:
 * @author: WS
 * @date 2020/12/13
 * @Version: 1.0
 **/
@Component
public class DateConverter implements Converter<String, Date> {
    private SimpleDateFormat simpleDateFormat=new SimpleDateFormat();
    @Override
    public Date convert(String s) {
        if (s!=null && !"".equals(s)){
            simpleDateFormat.applyPattern("yyyy-MM-dd");
            Date date = null;
            try {
                date = simpleDateFormat.parse(s);
                return date;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
